package com.xjj.service.controller;

import com.xjj.entity.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description 统一异常处理
 * @Author zhangjin
 * @Date 2022/10/20 12:02
 */
@RestControllerAdvice(basePackages = "com.xjj.service.controller")
public class GlobalAdvisor {
    @ExceptionHandler(Exception.class)
    public ResponseEntity handlerException(Exception e) {
        e.printStackTrace();
        String message = "系统维护中，请稍候再试";

        if (StringUtils.hasLength(e.getMessage())) {
            message = e.getMessage();
        }

        return ResponseEntity.FAIL(message, null);
    }
}
